package com.salmon.oss.thrift.client;

import com.salmon.thrift.OssHandlerService;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

public class OssThriftClient {

    private OssHandlerService.Client client;
    private TBinaryProtocol protocol;
    private TTransport transport;
    private String host;
    private int port;

    public OssThriftClient(String host, int port){
        this.host = host;
        this.port = port;
        init();
    }

    public void init() {
        transport = new TFastFramedTransport(new TSocket(host, port));
        protocol = new TBinaryProtocol(transport);
        client = new OssHandlerService.Client(protocol);
    }

    public OssHandlerService.Client getRPCThriftService() {
        return client;
    }

    public void open() throws TTransportException {
        transport.open();
    }

    public void close() {
        transport.close();
    }
}
